package com.example.swordkotlin

object Test22 {

    @JvmStatic
    fun main(args: Array<String>) {
        val pre = intArrayOf(1, 2, 4, 7, 3, 5, 6, 8)
        val vin = intArrayOf(4, 7, 2, 1, 5, 3, 8, 6)

        for (i in 0..3) {
            println(i)
        }

        for (i in 0 until 3) {
            println("---$i")
        }
    }

    class ListNode(var `val`: Int, var next: ListNode? = null)


    /**
     * 链表中倒数最后k个结点
     */

    fun FindKthToTail(pHead: ListNode?, k: Int): ListNode? {
        // write code here
        var pre = pHead
        var behind = pHead
        var count = 0
        while (pre != null) {
            if (count >= k) {
                behind = behind?.next
            }
            count++
            pre = pre.next
        }
        return if (k > count) null else behind
    }
}